package com.library.dcy.service;


import com.library.dcy.dao.LibraryDaoImpl;
import com.library.dcy.entity.Library;
import com.library.dcy.util.Page;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LibraryServiceImpl implements LibraryService{
    LibraryDaoImpl libraryDao=new LibraryDaoImpl();
    /**
     * 分页查询
     * @param name
     * @param currentPage
     * @return
     */
    @Override
    public Page<Library> findByPage(String name, Integer currentPage) {
        //创建分页对象
        Page<Library> page=new Page();
        //设置每页的显示行数
        page.setPageSize(10);
        //设置当前页数
        page.setCurrentPage(currentPage);
        //获取总记录调用Dao层区查询
        int i= 0;
        try {
            i = libraryDao.totalCount();
        } catch (Exception e) {
            e.printStackTrace();
        }
        page.setTotalCount(i);
        //根据当前页面查出起始下标
        Integer start=(currentPage-1)*page.getPageSize();
        Map<String,Object> map=new HashMap();
        map.put("name",name);
        map.put("start",start);
        map.put("pageSize",page.getPageSize());
        //调用dao查询当前页的数据集合
        List<Library> list= null;
        try {
            list = libraryDao.list(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //把查询到的list存入分页对象
        page.setList(list);
        return page;
    }
    /**
     * 补办
//     * @param reaId
//     * @param idCard
//     * @param pwd
//     * @param name
//     * @param age
//     * @param phone
//     * @param price
     * @return
     */
    @Override
    public boolean replace(Library library) {
        int replace = 0;
        try {
            replace = libraryDao.replace(library);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(replace==1){
            return true;
        }
        return false;
    }
    /**
     * 注销
     * @param reaId
     * @return
     */
    @Override
    public boolean findCancel(Integer reaId) {
        int cancel=libraryDao.cancel(reaId);
        if (cancel==1){
            return true;
        }
        return false;
    }
}
